﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JKF.Substructure;
using JKF.BusinessLayer.BLL;
using System.Data;

namespace JKF.Web.Sys.User
{
    public partial class User_View : PageBase
    {
        /// <summary>
        /// 店面下拉Select
        /// </summary>
        public string Shop_Code_Select
        {
            get { return new bllSHOP().GetShopArea(); }
        }
        /// <summary>
        /// 取得角色下拉Select
        /// </summary>
        public string SysRole_Select
        {
            get {
                string result = new bllSYS_ROLE().GetSysRoleArea(1);
                //if(result=="null")
                //{
                //    //ClientScript.RegisterStartupScript(this.GetType(),"Error","alert('获取角色下拉列表失败！\r\n可能原因此当前账户没有分配角色导致！')",true);
                //    return "";
                //}
                return result;
            }
        }
        /// <summary>
        /// 模块名称
        /// </summary>
        private const string module_name_en = "sys_user";
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //CheckPermission();
            MODULE_NAME_EN = "SYS_USER";
        }
        /// <summary>
        /// 检查操作权限
        /// </summary>
        private void CheckPermission()
        {
            bllPermission permission = new bllPermission();
            DataTable dt = permission.GetUserRolePermission();
            if (dt == null)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "tishi", "alert('获取操作权限失败！');closeWindow();", true);
                return;
            }
            DataRow[] dr = dt.Select(string.Format(" ROLE_KEY='{0}' and MODULE_NAME_EN='{1}' and ACTION_NAME='{2}'",bllSYS_USER.CurrentUser.ROLE_KEY.ToString(),module_name_en,SysConfig.Preview));
            base.Preview = dr.Length > 0;
            dr = dt.Select(string.Format(" ROLE_KEY='{0}' and MODULE_NAME_EN='{1}' and ACTION_NAME='{2}'",bllSYS_USER.CurrentUser.ROLE_KEY.ToString(),module_name_en,SysConfig.Add));
            base.Add = dr.Length > 0;
            dr = dt.Select(string.Format(" ROLE_KEY='{0}' and MODULE_NAME_EN='{1}' and ACTION_NAME='{2}'", bllSYS_USER.CurrentUser.ROLE_KEY.ToString(), module_name_en, SysConfig.Edit));
            base.Edit = dr.Length > 0;
            dr = dt.Select(string.Format(" ROLE_KEY='{0}' and MODULE_NAME_EN='{1}' and ACTION_NAME='{2}'", bllSYS_USER.CurrentUser.ROLE_KEY.ToString(), module_name_en, SysConfig.Delete));
            base.Delete = dr.Length > 0; 
            //permission.GetUserPermission(module_name_en, bllSYS_USER.CurrentUser.ROLE_KEY,ref base.Preview,ref base.Add,ref base.Edit,ref base.Delete);
            if (!base.Preview)
            {
                //关闭当前页面
                base.JavaScriptCloseWindow();
                return;
            } 
        }
         
    }
}